package com.ruoyi.project.lesson.lessonguide.service.impl;

import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.common.service.ICommonService;
import com.ruoyi.project.lesson.lessonguide.domain.LessonGuide;
import com.ruoyi.project.lesson.lessonguide.mapper.LessonGuideMapper;
import com.ruoyi.project.lesson.lessonguide.service.ILessonGuideService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程指引Service业务层处理
 *
 * @author shixiangwen
 * @date 2021-04-20
 */
@Service
@DataSource(DataSourceType.KKFORMULA)
public class LessonGuideServiceImpl implements ILessonGuideService {
    @Autowired
    private LessonGuideMapper lessonGuideMapper;

    @Autowired
    private ICommonService commonService;

    /**
     * 查询课程指引
     *
     * @param id 课程指引ID
     * @return 课程指引
     */
    @Override
    public LessonGuide selectLessonGuideById(Long id) {
        return lessonGuideMapper.selectLessonGuideById(id);
    }

    /**
     * 查询课程指引列表
     *
     * @param lessonGuide 课程指引
     * @return 课程指引
     */
    @Override
    public List<LessonGuide> selectLessonGuideList(LessonGuide lessonGuide) {
        return lessonGuideMapper.selectLessonGuideList(lessonGuide);
    }

    /**
     * 新增课程指引
     *
     * @param lessonGuide 课程指引
     * @return 结果
     */
    @Override
    public int insertLessonGuide(LessonGuide lessonGuide) {
        return lessonGuideMapper.insertLessonGuide(lessonGuide);
    }

    /**
     * 修改课程指引
     *
     * @param lessonGuide 课程指引
     * @return 结果
     */
    @Override
    public int updateLessonGuide(LessonGuide lessonGuide) {
        return lessonGuideMapper.updateLessonGuide(lessonGuide);
    }

    /**
     * 删除课程指引对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteLessonGuideByIds(String ids) {
        return lessonGuideMapper.deleteLessonGuideByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除课程指引信息
     *
     * @param id 课程指引ID
     * @return 结果
     */
    @Override
    public int deleteLessonGuideById(Long id) {
        return lessonGuideMapper.deleteLessonGuideById(id);
    }

    @Override
    public int getMaxSort(Long lessonId) {
        return commonService.selectTableColumnMaxValue("lesson_guide", "sort", " lesson_id = " + lessonId) + 1;
    }
}
